package com.bw1806.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.bw1806.mapper.TbOrderMapper;
import com.bw1806.pojo.TbOrder;
import com.bw1806.pojo.TbOrderExample;
import com.bw1806.sellergoods.service.TbOrderService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/11/1115:02
 */
@Service(timeout = 5000,retries = 0)
public class TbOrderServiceImpl implements TbOrderService {

    @Autowired
    private TbOrderMapper tbOrderMapper;

    @Override
    public List<TbOrder> findAll() {
        return tbOrderMapper.selectByExample(null);
    }

    @Override
    public PageResult<TbOrder> pagelist(TbOrder tbOrder,int pageNum,int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        TbOrderExample example=new TbOrderExample();

        TbOrderExample.Criteria criteria = example.createCriteria();

        if(tbOrder!=null){
            //if(tbOrder.getName()!=null && tbOrder.getName().length()>0){
            //    criteria.andNameLike("%"+tbOrder.getName()+"%");
           // }
        }

        Page<TbOrder> page= (Page<TbOrder>) tbOrderMapper.selectByExample(example);

        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void save(TbOrder tbOrder) {
        Long id = tbOrder.getOrderId();
        if(id != null && id !=0){
            tbOrderMapper.updateByPrimaryKey(tbOrder);
        } else{
            tbOrderMapper.insert(tbOrder);
        }
    }

    @Override
    public TbOrder getById(Long id) {
        return tbOrderMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deletebth(Long[] ids) {
       for(long id : ids){
            tbOrderMapper.deleteByPrimaryKey(id);
        }
        //tbOrderMapper.deletebth(ids);
    }
}
